package com.yipingnai.blog.controller.admin;

import com.yipingnai.blog.model.PV;
import com.yipingnai.blog.model.RespBean;
import com.yipingnai.blog.service.ArticleService;
import com.yipingnai.blog.service.PVService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author: 一瓶奶
 * @Url: www.yipingnai.cn
 * @Date: 2020/6/21 14:48
 */
@RestController
@RequestMapping("/admin/info")
public class AdminBlogInfoController {

    @Autowired
    PVService pvService;

    @Autowired
    ArticleService articleService;
    // 获取所有访问量
    @GetMapping("/")
    public RespBean getAllPageView() {
        Map<String, Object> result = new HashMap<>();
        // 文章总数
        Integer arTotal = articleService.getTotal();
        result.put("arTotal", arTotal);
        // 本月发表文章总数
        Integer arCountMonth = articleService.getCountMonth();
        result.put("arCountMonth", arCountMonth);
        // 本周发表文章总数
        Integer arCountWeek = articleService.getCountWeek();
        result.put("arCountWeek", arCountWeek);
        // pv总数
        Integer pvPageViews = pvService.getAllPageView();
        result.put("pvPageViews", pvPageViews);
        // 本月pv总数
        Integer pageViewMonth = pvService.getPageViewMonth();
        result.put("pageViewMonth", pageViewMonth);
        // 本周pv总数
        Integer pageViewWeek = pvService.getPageViewWeek();
        result.put("pageViewWeek", pageViewWeek);
        // 近七天pv
        List<PV> pageViewSeven = pvService.getPageViewSeven();
        result.put("pageViewSeven", pageViewSeven);
        if(result != null){
            return RespBean.ok("获取总数成功", result);
        }
        return  RespBean.error("获取失败");
    }

}
